/** @format */

import { resultsModel } from '../../../sdk'
import { CODE_TYPES } from '../../../errorCode'
import { GAME_TYPE } from '../../../constants';

export default async function checkTaskLimit(
  context: IContext<IParams>,
  { userInfo }: IControllerInfos
) {
  const { taskLimit, type, game } = context.data
  const { todayLotTaskCompleteTimes, todayBlessTaskCompleteTimes } = userInfo;
  
  const completeTotal = GAME_TYPE.DRAW_LOTS === game ? todayLotTaskCompleteTimes : todayBlessTaskCompleteTimes

  if (type !== 'shareForHelp' && completeTotal >= +taskLimit) {
    return resultsModel.error(CODE_TYPES.ERROR_TASK_LIMIT)
  }
}
